/**
 * LocalDateTimeSerializer.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2015年1月20日
 */
package com.pshare.framework.databind;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * localDateTime to json
 */
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
	
	private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

	@Override
	public void serialize(LocalDateTime date, JsonGenerator generator, SerializerProvider provider) throws IOException,
			JsonProcessingException {

		String dateString = date.format(formatter);
		generator.writeString(dateString);
	}
}
